define(function(require,exports,module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/component/tree.js");
	require("resource/js/jquery.media.js");
	var ajax = require("resource/js/component/ajax.js");
	var easyCombox = require("resource/js/component/easycombobox.js");
	var EASYUTIL = require("resource/js/component/easyutil.js");
	var CREATEBTN = require("resource/js/component/createbutton.js");
	require("resource/js/ueditor_old/themes/default/css/ueditor.css");
	easyCombox.create({
		url:BASEPATH+"/base/authoriza/basecode/getType.htm",
		param:{checkeds:"signature"}
	});
	
	var config = {
			type:"unit",
			name:"签章信息",
			column:[[
				{field:'id',title:'ID',width:100,align:'center',height:50,hidden:true},
				{field:'relatedId',title:'所属企业',width:100,align:'center',height:50,hidden:true},
				{field:'sigType',title:'签章类型',width:100,align:'center',height:50},
				{field:'sigPath',title:'签章图片',width:100,align:'center',height:50,formatter:function(value,row,index){
					if(value!=""&&value!=null&&value!=undefined){
						return "<img class='sig' id='signature' style='cursor: pointer;' onclick=window.open('"+BASEPATH+value+"') src='"+BASEPATH+value+"' width='150px' height='150px'/>";
					}else{
						return '';
					}
				}}
			]]
	};
	/*$(function(){
		var size = 2.0*$("#signature").width();
		$("#signature").mouseover(function(event){
			var $target = $(event.target);
			if($target.is('img')){
				$("<img id = 'tip' src='"+$target.attr("src")+"'>").css({"height":size,"width":size}).appendTo($("#imgPreview"));
			}
		}).mouseout(function(){
			$("#tip").remove();
		})
	})*/
	$("#dg").on('.sig','hover',function(){
		debugger;
		$(".sig").css({"width":250,"height":250});
//		},function(){
//		    $(".sig").css({"width":150,"height":150});
//		});
	})
//	$("#signature").hover(function(){	
//		debugger;
//	    $(".sig").css({"width":250,"height":250});
//	},function(){
//	    $(".sig").css({"width":150,"height":150});
//	});

	var dgutil = undefined;
	var datagridconfig = undefined;
	var initSigImg = function(arg){
		using("upload",function(){
			$("#addsigdownloadUrl").upload({
				buttonText:'选择签章',
			    iconCls:'icon-man', 
			    edit:true,
			    iconAlign:'left',
			    title:"上传签章图片",
			    param: {
					exts: "png,jpg,bmp,gif"
				},
				onClickButton:function(){
					$("#addsigdownloadUrl").upload("show");
				},
				onSuccessAfter:function(files){
					$("#sigAttachmentFilePath").val(files[0].fileUrl);
					$(this).textbox("setValue",files[0].fileName + "." + files[0].fileExt);
					$("#sigAttachmentName").val(files[0].fileName + "." + files[0].fileExt);
					$("#sigAttachmentFileExt").val(files[0].fileExt);
				}
			});
		});
			
	};
	initSigImg();
	
	//上传签章
	var addDialogInit = function(baseUrl,row){
		$("#adddlg").dialog({
			iconCls:'icon-save',
			title:'签章上传',
			href:baseUrl,
			onLoad:function(){
				initSigImg();
				initPage();
			},
			buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					var sigType = $("#signatureType").combobox("getText");
					var sigPath = $("#sigAttachmentFilePath").val();
					if(sigType=="请选择"){
						$.messager.alert('系统消息','请选择签章类型！');
						return;
					}
					if(sigPath==null||sigPath==undefined||sigPath==""){
						$.messager.alert('系统消息','请上传签章图片！');
						return;
					}
					ajax.init().success(function(code,msg,data){
						if(code==0){
							$.messager.show({
								title:"系统提示",
								msg:"上传成功！",
								timeout:3000,
								showType:"slide"
							});
							$("#adddlg").dialog("close");
							initPage();
						}else{
							$.messager.show({
								title:"系统提示",
								msg:"上传失败！",
								timeout:3000,
								showType:"slide"
							});
						}
					}).post(BASEPATH+"/sig/signature/save.htm",{sigPath:sigPath,sigType:sigType});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$("#adddlg").dialog("close");
				}
			}]
		});
		$("#adddlg").dialog("open");
	}
	
	//删除
	var delInit=function(baseUrl,rows){
		$.messager.confirm('系统提示','删除该签章会影响审批流程状态，确定要删除么？',function(r){
			if(r){
				var sigIds = "";
		for(var key in rows){
			if(key==rows.length-1){
				sigIds += rows[key].id;
			}else{
				sigIds += rows[key].id+",";
			}
		}
		EASYUTIL.ajaxHandler(baseUrl,{sigId:sigIds},function(code,msg,data){
			if(code==0){
				$.messager.show("系统消息：","删除成功");
			}else{
				$.messager.show("系统消息：","删除失败");
			}
			dgutil.pager(1);
		});
					dgutil.delRow(rows);	
			}
		})
		
	}
	
	function initPage(){
			easyCombox.init({ ele:"#signatureType",grouptype:"signature"});
			dgutil = new EASYUTIL.ajaxDataGrid(datagridconfig);
			};
			
	module.exports={
			trans:function(){
				var buttons={
						title:{
							_class:"",
							text:config.name+"列表"
						},
						btn:[
						       {
								iconCls: 'icon-upload-blue',
								url:'/view/oa/approval/E_Signature/updSignature',
								text:"上传签章",
								addClass:'l-btn-display',
								handler:  addDialogInit,
						       },
						       {
								iconCls: 'icon-remove',
								url:'/sig/signature/delete.htm',
								text:"删除",
								addClass:'l-btn-display',
								needRows:true,
								/*isCheck:true,*/
								handler: delInit
								}
						]};
				datagridconfig = {
						fitColumns: true,
						singleSelect: false,
						striped: true,
						autoRowHeight: false,
						fit: true,
						url:BASEPATH+"/sig/signature/listall.htm",
						toolbar:buttons,
						columns:config.column,
						eid:"dg",
						args:"updform"	
				};
				using(["parser","dialog","datebox","combobox","ztreebox","datagrid"],function(){
					initPage();				
				});
			}
	}

});

